package o;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import java.lang.reflect.Field;

public class cep {
    private static int ˎ;
    private static Field ˏ;
    private static String ॱ = "PackageManager";

    public enum d {
        SYSTEM_APP,
        SYSTEM_UPADTE_APP,
        PREINSTALLAPP,
        NORMAL,
        UNKNOW
    }

    static {
        ˏ = null;
        ˎ = 0;
        try {
            ˏ = ApplicationInfo.class.getField("hwFlags");
        } catch (NoSuchFieldException e) {
            Logger.ˎ(ॱ, "do not have hwFlags filed");
        }
        ˎ = ʻ();
    }

    public static boolean ˋ(Context context, @NonNull String str) {
        return ((cdg) cdb.ॱ(cdg.class)).ॱॱ(str);
    }

    @Deprecated
    public static boolean ॱ() {
        return ((ceq) cdb.ॱ(ceq.class)).ˎ(ContentManager.getInstant().getContext());
    }

    public static boolean ˏ() {
        return ((ceq) cdb.ॱ(ceq.class)).ˎ(ContentManager.getInstant().getContext());
    }

    public static boolean ˋ() {
        return false;
    }

    public static boolean ˊ() {
        return false;
    }

    public static boolean ॱ(boolean z) {
        return ˎ();
    }

    public static boolean ˎ() {
        return ((duh) cdb.ॱ(duh.class)).ˎ();
    }

    public static boolean ˊ(Context context, @NonNull String str) {
        return ((cdg) cdb.ॱ(cdg.class)).ॱॱ(str);
    }

    public static boolean ˏ(Context context, String str) {
        if (context.getPackageManager().queryIntentActivities(new Intent(str), WXMediaMessage.THUMB_LENGTH_LIMIT).size() > 0) {
            return true;
        }
        Logger.ˋ(ॱ, "isIntentExisting action:" + str + ",false");
        return false;
    }

    public static d ˎ(@Nullable String str) {
        if (TextUtils.isEmpty(str)) {
            return d.UNKNOW;
        }
        try {
            return ˏ(ContentManager.getInstant().getContext().getPackageManager().getApplicationInfo(str, DnsConfig.MAX_CACHE_ENTRIES));
        } catch (Exception e) {
            return d.UNKNOW;
        }
    }

    public static d ˊ(PackageInfo packageInfo) {
        if (packageInfo == null || packageInfo.applicationInfo == null) {
            return d.UNKNOW;
        }
        return ˏ(packageInfo.applicationInfo);
    }

    private static d ˏ(ApplicationInfo applicationInfo) {
        if (applicationInfo == null) {
            return d.UNKNOW;
        }
        if (ˏ != null) {
            try {
                int intValue = ((Integer) ˏ.get(applicationInfo)).intValue();
                if (!(intValue == -1 || (applicationInfo.flags & 1) == 0 || (intValue & 33554432) == 0)) {
                    return d.PREINSTALLAPP;
                }
            } catch (IllegalArgumentException e) {
                Logger.ˋ(ॱ, "getAppType(String packageName) " + e.toString());
            } catch (IllegalAccessException e2) {
                Logger.ˋ(ॱ, "getAppType(String packageName) " + e2.toString());
            } catch (Exception e3) {
                Logger.ˋ(ॱ, "getAppType(String packageName) " + e3.toString());
            }
        }
        if ((applicationInfo.flags & 1) != 0 && (applicationInfo.flags & ˎ) != 0) {
            return d.PREINSTALLAPP;
        }
        if ((applicationInfo.flags & DnsConfig.MAX_CACHE_ENTRIES) != 0) {
            return d.SYSTEM_UPADTE_APP;
        }
        if ((applicationInfo.flags & 1) != 0) {
            return d.SYSTEM_APP;
        }
        return d.NORMAL;
    }

    private static int ʻ() {
        int i = 0;
        try {
            Class cls = Class.forName("android.content.pm.PackageParser");
            i = cls.getDeclaredField("PARSE_IS_REMOVABLE_PREINSTALLED_APK").getInt(cls);
        } catch (ClassNotFoundException e) {
            Logger.ˋ(ॱ, "do Not have PackageParser");
        } catch (SecurityException e2) {
            Logger.ˋ(ॱ, "can not access PARSE_IS_REMOVABLE_PREINSTALLED_AP");
        } catch (NoSuchFieldException e3) {
            Logger.ˎ(ॱ, "do not have PARSE_IS_REMOVABLE_PREINSTALLED_AP");
        } catch (IllegalArgumentException e4) {
            Logger.ˋ(ॱ, "IllegalArgumentException");
        } catch (IllegalAccessException e5) {
            Logger.ˋ(ॱ, "IllegalAccessException");
        }
        return i;
    }

    public static int ˎ(@NonNull PackageInfo packageInfo) {
        if ((packageInfo.applicationInfo.flags & 1) == 0) {
            return 0;
        }
        if (ˎ(packageInfo.applicationInfo)) {
            return 1;
        }
        return 2;
    }

    private static boolean ˎ(ApplicationInfo applicationInfo) {
        int i = applicationInfo.flags;
        Integer ˋ = erz.ˋ();
        if (ˋ != null && (i & ˋ.intValue()) != 0) {
            return true;
        }
        Field ˏ = erz.ˏ();
        if (ˏ != null) {
            try {
                if ((ˏ.getInt(applicationInfo) & 33554432) != 0) {
                    return true;
                }
            } catch (IllegalAccessException e) {
                Logger.ˏ(ॱ, "can not get hwflags" + e.toString());
            } catch (IllegalArgumentException e2) {
                Logger.ˏ(ॱ, "can not get hwflags" + e2.toString());
            }
        }
        return false;
    }
}
